define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'form_student/index' + location.search,
                    add_url: 'form_student/add',
                    edit_url: 'form_student/edit',
                    del_url: 'form_student/del',
                    multi_url: 'form_student/multi',
                    table: 'form_student',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'openid', title: __('Openid')},
                        {field: 'classid', title: __('Classid')},
                        {field: 'nickname', title: __('Nickname')},
                        {field: 'birthday', title: __('Birthday')},
                        {field: 'sid', title: __('Sid')},
                        {field: 'gender', title: __('Gender')},
                        {field: 'classname', title: __('Classname')},
                        {field: 'tel', title: __('Tel')},
                        {field: 'family_address', title: __('Family_address')},
                        {field: 'current_address', title: __('Current_address')},
                        {field: 'a_9', title: __('A_9')},
                        {field: 'a_10', title: __('A_10')},
                        {field: 'a_10_1', title: __('A_10_1')},
                        {field: 'a_10_2', title: __('A_10_2')},
                        {field: 'a_10_3', title: __('A_10_3')},
                        {field: 'a_10_4', title: __('A_10_4')},
                        {field: 'a_10_5', title: __('A_10_5')},
                        {field: 'a_10_6', title: __('A_10_6')},
                        {field: 'a_11', title: __('A_11')},
                        {field: 'a_11_1', title: __('A_11_1')},
                        {field: 'a_11_2', title: __('A_11_2')},
                        {field: 'a_11_3', title: __('A_11_3')},
                        {field: 'a_11_4', title: __('A_11_4')},
                        {field: 'a_11_5', title: __('A_11_5')},
                        {field: 'a_12', title: __('A_12')},
                        {field: 'a_12_1', title: __('A_12_1')},
                        {field: 'a_12_2', title: __('A_12_2')},
                        {field: 'a_12_3', title: __('A_12_3')},
                        {field: 'a_12_4', title: __('A_12_4')},
                        {field: 'a_12_5', title: __('A_12_5')},
                        {field: 'a_13', title: __('A_13')},
                        {field: 'a_14', title: __('A_14')},
                        {field: 'a_15', title: __('A_15')},
                        {field: 'a_16', title: __('A_16')},
                        {field: 'a_16_1', title: __('A_16_1')},
                        {field: 'a_16_2', title: __('A_16_2')},
                        {field: 'a_16_3', title: __('A_16_3')},
                        {field: 'a_16_4', title: __('A_16_4')},
                        {field: 'a_16_5', title: __('A_16_5')},
                        {field: 'a_16_6', title: __('A_16_6')},
                        {field: 'a_17', title: __('A_17')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        sea: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'form_student/sea' + location.search,
                    add_url: 'form_student/add',
                    edit_url: 'form_student/edit',
                    del_url: 'form_student/del',
                    multi_url: 'form_student/multi',
                    table: 'form_student',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: '', title: __('序号'),operate:false,table:table,formatter: Table.api.formatter.natureorder},
                        //{field: 'openid', title: __('Openid'),operate:false},
                        // {field: 'classid', title: __('Classid'),operate:false},
                        {field: 'nickname', title: __('Nickname'),operate:false},
                        {field: 'birthday_time', title: __('Birthday'),operate:false,formatter: Table.api.formatter.datestr},
                        {field: 'sid', title: __('Sid'),operate:false},
                        {field: 'gender', title: __('Gender'),operate:false,formatter: function (value, row, index) {
                                var str = "";
                                switch(row.gender){
                                    case 1:
                                        str = '男';
                                        break;
                                    case 2:
                                        str = '女';
                                        break;
                                    default:
                                        str = '-';
                                }
                                return str;
                            }},
                        {field: 'classes_name', title: __('Classname'),operate:false},
                        {field: 'tel', title: __('Tel'),operate:false},
                        {field: 'family_address', title: __('Family_address'),operate:false},
                        {field: 'current_address', title: __('Current_address'),operate:false},
                        {field: 'address', title: '微信地址',operate:false},
                        {field: 'a_9', title: __('A_9'),operate:false,formatter: Table.api.formatter.yesorno},
                        {field: 'a_10', title: __('A_10'),operate:false,formatter: Table.api.formatter.yesorno},
                        {field: 'a_10_1', title: __('A_10_1'),operate:false, formatter: Table.api.formatter.datetime},
                        {field: 'a_10_2', title: __('A_10_2'),operate:false, formatter: Table.api.formatter.datetime},
                        {field: 'a_10_3', title: __('A_10_3'),operate:false},
                        {field: 'a_10_4', title: __('A_10_4'),operate:false},
                        {field: 'a_10_5', title: __('A_10_5'),operate:false,formatter: Table.api.formatter.yesorno},
                        {field: 'a_10_6', title: __('A_10_6'),operate:false,formatter: Table.api.formatter.yesorno},
                        {field: 'a_11', title: __('A_11'),operate:false,formatter: Table.api.formatter.yesorno},
                        {field: 'a_11_1', title: __('A_11_1'),operate:false, formatter: Table.api.formatter.datetime},
                        {field: 'a_11_2', title: __('A_11_2'),operate:false},
                        {field: 'a_11_3', title: __('A_11_3'),operate:false,formatter: Table.api.formatter.yesorno},
                        {field: 'a_11_4', title: __('A_11_4'),operate:false,formatter: Table.api.formatter.yesorno},
                        {field: 'a_11_5', title: __('A_11_5'),operate:false,formatter: Table.api.formatter.yesorno},
                        {field: 'a_12', title: __('A_12'),operate:false,formatter: Table.api.formatter.yesorno},
                        {field: 'a_12_1', title: __('A_12_1'),operate:false, formatter: Table.api.formatter.datetime},
                        {field: 'a_12_2', title: __('A_12_2'),operate:false},
                        {field: 'a_12_3', title: __('A_12_3'),operate:false,formatter: Table.api.formatter.yesorno},
                        {field: 'a_12_4', title: __('A_12_4'),operate:false,formatter: Table.api.formatter.yesorno},
                        {field: 'a_12_5', title: __('A_12_5'),operate:false,formatter: Table.api.formatter.yesorno},
                        {field: 'a_13', title: __('A_13'),operate:false,formatter: Table.api.formatter.yesorno},
                        {field: 'a_14', title: __('A_14'),operate:false,formatter: Table.api.formatter.yesorno},
                        {field: 'a_15', title: __('A_15'),operate:false,formatter: Table.api.formatter.yesorno},
                        {field: 'a_16', title: __('A_16'),operate:false,formatter: Table.api.formatter.yesorno},
                        {field: 'a_16_1', title: __('A_16_1'),operate:false},
                        {field: 'a_16_2', title: __('A_16_2'),operate:false},
                        {field: 'a_16_3', title: __('A_16_3'),operate:false},
                        {field: 'a_16_4', title: __('A_16_4'),operate:false, formatter: Table.api.formatter.datetime},
                        {field: 'a_16_5', title: __('A_16_5'),operate:false, formatter: Table.api.formatter.datetime},
                        {field: 'a_16_6', title: __('A_16_6'),operate:false,formatter: Table.api.formatter.yesorno},
                        {field: 'a_17', title: __('A_17'),operate:false,formatter: Table.api.formatter.yesorno},
                        {field: 'create_time', title: __('时间'),visiable:false,operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},

                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});